from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.firefox import GeckoDriverManager


class DriverFactory:
    @staticmethod
    def create_driver(browser_name, headless=False, window_size=None):
        if browser_name.lower() == "chrome":
            options = webdriver.ChromeOptions()
            # if headless:
            #     options.add_argument("--headless")
            if window_size:
                options.add_argument(f"--window-size={window_size}")
            service = Service(ChromeDriverManager().install())
            return webdriver.Chrome(service=service, options=options)

        elif browser_name.lower() == "firefox":
            options = webdriver.FirefoxOptions()
            if headless:
                options.add_argument("--headless")
            service = Service(GeckoDriverManager().install())
            return webdriver.Firefox(service=service, options=options)

        else:
            raise ValueError(f"Unsupported browser: {browser_name}")